package UILayer;


import java.util.Scanner;

import CtrLayer.KundeCtr;
import ModelLayer.Kunde;

public class KundeUI {
	private KundeCtr kCtr;
	
	/**
	 * Constructor for the KundeUI that
	 * instances the KundeCtr class
	 * */
	public KundeUI()
	{
		try{
			kCtr = new KundeCtr();
		}catch(Exception e){
			System.out.println("cant instanciate kundeCtr");
		}
	}
	
	public void startKundeUI()
	{
		boolean start = false;
		while(!start){
			Scanner input = new Scanner(System.in);
			System.out.println("1. Create new Kunde");
			System.out.println("2. Find Kunde");
			System.out.println("3. Edit Kunde");
			//System.out.println("");
			//System.out.println("");
			int choice = input.nextInt();
			
			switch(choice){
				case 1:
					createNewKunde();
					break;
				case 2:
					findKunde();
					break;
				case 3:
					editKunde();
					break;
				default:
					start = true;
					break;
				
			}
		}
	}
	
	/**
	 * Create new kunde method
	 * Asks for inputs of the costumer.
	 * */
	public void createNewKunde()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Name: ");
		String name = input.next();
		input.nextLine();
		System.out.println("Account: ");
		String acc = input.next();
		input.nextLine();
		System.out.println("Address: ");
		String add = input.next();
		input.nextLine();
		System.out.println("Phone: ");
		String phone = input.next();
		input.nextLine();
		System.out.println("Costumer discount(In percent): ");
		int dis = input.nextInt();
		input.nextLine();
		System.out.println("E-mail: ");
		String email = input.next();
		/**
		 * Create new Kunde object and add it to the container.
		 * @param String navn, String konto, String adresse, String tlf, int kunderabat, String email
		 * */
		kCtr.createNewKunde(name, acc, add, phone, dis, email);
		System.out.println("Costumer added to system!");
	}
	
	/**
	 * Find kunde
	 * Finds a kunde in system.
	 * */
	public void findKunde()
	{
		Scanner input = new Scanner(System.in);
		System.out.println("Enter tlf: ");
		String tlf = input.next();
		Kunde k = kCtr.findKunde(tlf);
		System.out.println("Name: " + k.getNavn());
		System.out.println("Phone: " + k.getTlf());
		System.out.println("Address: " + k.getAddresse());
		System.out.println("Email: " + k.getEmail());
	}
	/**
	 * Edit kunde 
	 * 
	 * */
	public void editKunde()
	{
		EditKundeUI ekui = new EditKundeUI();
		ekui.startNewEditKundeUI();
	}
	
}
